home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Games / Doom / ADoom-0.8 / ADoom_src / amiga_system.c < prev    next >
C/C++ Source or Header  |  1998-06-24  |  5KB  |  201 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdarg.h>
  6. #include <time.h>
  7.  
  8. #include <exec/exec.h>
  9. #include <proto/exec.h>
  10.  
  11. #include "doomdef.h"
  12. #include "m_misc.h"
  13. #include "i_system.h"
  14. #include "i_video.h"
  15. #include "i_sound.h"
  16.  
  17. #include "d_net.h"
  18. #include "g_game.h"
  19. #include "m_argv.h"
  20.  
  21. void amiga_getevents (void);
  22.  
  23. #define MIN_ZONESIZE  (2*1024*1024)
  24. #define MAX_ZONESIZE  (6*1024*1024)
  25.  
  26. /**********************************************************************/
  27. // Called by DoomMain.
  28. void I_Init (void)
  29. {
  30.   int p, taskpriority;
  31.  
  32.   taskpriority = -5;
  33.   p = M_CheckParm ("-taskpriority");
  34.   if (p && p < myargc - 1) {
  35.     taskpriority = atoi (myargv[p+1]);
  36.   }
  37.   SetTaskPri (FindTask(NULL), taskpriority);
  38.  
  39.   I_InitSound ();
  40.   I_InitMusic ();
  41.   //  I_InitGraphics ();
  42. }
  43.  
  44. /**********************************************************************/
  45. // Called by startup code
  46. // to get the ammount of memory to malloc
  47. // for the zone management.
  48. byte*    I_ZoneBase (int *size)
  49. {
  50.   byte *zone;
  51.   ULONG memfree, largest;
  52.   int p;
  53.  
  54.   memfree = AvailMem (MEMF_FAST);
  55.   largest = AvailMem (MEMF_FAST | MEMF_LARGEST);
  56.   printf ("Memfree = %d, largest = %d\n", memfree, largest);
  57.  
  58.   p = M_CheckParm ("-heapsize");
  59.   if (p && p < myargc - 1) {
  60.  
  61.     *size = 1024 * atoi (myargv[p+1]);
  62.  
  63.   } else {
  64.  
  65.     if (largest > MAX_ZONESIZE + 65536 &&
  66.         memfree > MAX_ZONESIZE + (2 * 1024 * 1024))
  67.       *size = MAX_ZONESIZE;
  68.     else if (memfree < largest + (2 * 1024 * 1024))
  69.       *size = memfree - (2 * 1024 * 1024) - 65536;
  70.     else
  71.       *size = largest - 65536;
  72.  
  73.     if (*size < MIN_ZONESIZE)
  74.       I_Error ("Unable to allocate at least %d fastmem for zone management\n"
  75.                "while leaving 2Mb fastmem free\n"
  76.                "Fastmem free = %d, largest block = %d",
  77.                MIN_ZONESIZE, memfree, largest);
  78.   }
  79.  
  80.   if ((zone = (byte *)malloc(*size)) == NULL)
  81.     I_Error ("malloc() %d bytes for zone management failed", *size);
  82.  
  83.   printf ("I_ZoneBase(): Allocated %d bytes for zone management\n", *size);
  84.  
  85.   return zone;
  86. }
  87.  
  88. /**********************************************************************/
  89. // Called by D_DoomLoop,
  90. // returns current time in tics.
  91. int I_GetTime (void)
  92. {
  93.   int newtics;
  94.   static int basetime=0;
  95.   unsigned int clock[2];
  96.  
  97.   timer (clock);
  98.   if (!basetime)
  99.     basetime = clock[0];
  100.   newtics = (clock[0]-basetime)*TICRATE + clock[1]*TICRATE/1000000;
  101.   return newtics;
  102. }
  103.  
  104. /**********************************************************************/
  105. //
  106. // Called by D_DoomLoop,
  107. // called before processing any tics in a frame
  108. // (just after displaying a frame).
  109. // Time consuming syncronous operations
  110. // are performed here (joystick reading).
  111. // Can call D_PostEvent.
  112. //
  113. void I_StartFrame (void)
  114. {
  115.   amiga_getevents ();
  116. }
  117.  
  118. /**********************************************************************/
  119. //
  120. // Called by D_DoomLoop,
  121. // called before processing each tic in a frame.
  122. // Quick syncronous operations are performed here.
  123. // Can call D_PostEvent.
  124. void I_StartTic (void)
  125. {
  126. }
  127.  
  128. /**********************************************************************/
  129. // Asynchronous interrupt functions should maintain private queues
  130. // that are read by the synchronous functions
  131. // to be converted into events.
  132.  
  133. // Either returns a null ticcmd,
  134. // or calls a loadable driver to build it.
  135. // This ticcmd will then be modified by the gameloop
  136. // for normal input.
  137. ticcmd_t    emptycmd;
  138. ticcmd_t* I_BaseTiccmd (void)
  139. {
  140.   return &emptycmd;
  141. }
  142.  
  143. /**********************************************************************/
  144. // Called by M_Responder when quit is selected.
  145. // Clean exit, displays sell blurb.
  146. void I_Quit (void)
  147. {
  148.   D_QuitNetGame ();
  149.   I_ShutdownSound();
  150.   I_ShutdownMusic();
  151.   M_SaveDefaults ();
  152.   I_ShutdownGraphics();
  153.   exit(0);
  154. }
  155.  
  156. /**********************************************************************/
  157. // Allocates from low memory under dos,
  158. // just mallocs under unix
  159. byte* I_AllocLow (int length)
  160. {
  161.   byte*    mem;
  162.  
  163.   if ((mem = (byte *)malloc (length)) == NULL)
  164.     I_Error ("Out of memory allocating %d bytes", length);
  165.   memset (mem,0,length);
  166.   return mem;
  167. }
  168.  
  169. /**********************************************************************/
  170. void I_Tactile (int on, int off, int total)
  171. {
  172.   // UNUSED.
  173.   on = off = total = 0;
  174. }
  175.  
  176. /**********************************************************************/
  177. void I_Error (char *error, ...)
  178. {
  179.   va_list    argptr;
  180.  
  181.   // Message first.
  182.   va_start (argptr, error);
  183.   fprintf (stderr, "Error: ");
  184.   vfprintf (stderr, error, argptr);
  185.   fprintf (stderr, "\n");
  186.   va_end (argptr);
  187.  
  188.   fflush (stderr);
  189.  
  190.   // Shutdown. Here might be other errors.
  191.   if (demorecording)
  192.     G_CheckDemoStatus ();
  193.  
  194.   D_QuitNetGame ();
  195.   I_ShutdownGraphics ();
  196.  
  197.   exit (20);
  198. }
  199.  
  200. /**********************************************************************/
  201.